import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TilePanel } from "../../equipment/TilePanel";
import { ArenaCrossFinalMyBattlesCellRenderer } from "./cell/ArenaCrossFinalMyBattlesCellRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { SArenaCrossBattleRecords } from "../../../../../Message/Public/SArenaCrossBattleRecords";
type int = number;
//class ArenaCrossFinalMyBattlesWindows
    
    export  class ArenaCrossFinalMyBattlesWindows extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._ary = [];
            setSize(500, 440);
            titleHeight = 27;
            title = Language.getString(44281);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        protected onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGetMyBattleRecords));
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._sp = new Object /* flash.display.Sprite */();
            this._sp.x = 18;
            this._sp.y = 38;
            addChild(this._sp);
            ObjCreate.createBg(0, 0, 464, 368, this._sp);
            ObjCreate.createTextField(Language.getString(44316), 53, 8, 40, 20, this._sp, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(44317), 242, 8, 40, 20, this._sp, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(44318), 406, 8, 40, 20, this._sp, GlobalStyle.textFormat6);
            this._tfNoRecord = ObjCreate.createTextField(Language.getString(44240), 218, 208, 200, 20, this, GlobalStyle.textFormat6);
            this._tfNoRecord.visible = true;
            this._tileList = new TilePanel();
            this._tileList.setSize(450, 330);
            this._tileList.rowHeight = 33;
            this._tileList.columnWidth = 445;
            this._tileList.setStyle("cellRenderer", ArenaCrossFinalMyBattlesCellRenderer);
            this._tileList.x = 2;
            this._tileList.y = 28;
            this._sp.addChild(this._tileList);
            this._tileList.visible = false;
            this._pagebar = new PageSelecter();
            this._pagebar.mode = PageSelecter.CompleteMode;
            this._pagebar.move(165, 371);
            this._pagebar.currentPage = 1;
            this._pagebar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            this._sp.addChild(this._pagebar);
            return;
        }

        protected onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._ary.length > 0) 
            {
                this.updateShowModel(this._ary);
            }
            return;
        }

        /* internal  */updateShowModel(arg1: Array<any>): void
        {
            this._pagebar.maxPage = Math.ceil(arg1.length / this._pagesize);
            var loc1=(this._pagebar.currentPage - 1) * this._pagesize;
            var loc2=this._pagebar.currentPage * this._pagesize > arg1.length ? arg1.length : this._pagebar.currentPage * this._pagesize;
            var loc3=arg1.slice(loc1, loc2);
            this._tileList.dataProvider = new DataProvider(loc3);
            return;
        }

        public updateInfo(arg1: SArenaCrossBattleRecords): void
        {
            this._ary = arg1.records.concat();
            this.updateShowModel(this._ary);
            var loc1=this._ary.length > 0;
            this._tileList.visible = loc1;
            this._tfNoRecord.visible = !loc1;
            return;
        }

        public static get instance(): ArenaCrossFinalMyBattlesWindows
        {
            if (!ArenaCrossFinalMyBattlesWindows._instance) 
            {
                ArenaCrossFinalMyBattlesWindows._instance = new ArenaCrossFinalMyBattlesWindows();
            }
            return ArenaCrossFinalMyBattlesWindows._instance;
        }

        /* internal */ /* var */_sp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfNoRecord: Object /* flash.text.TextField */;

        /* internal */ /* var */_tileList: TilePanel;

        /* internal */ /* var */_pagebar: PageSelecter;

        /* internal */ /* var */_ary: Array<any>;

        /* internal */ /* var */_pagesize: int=10;

        /* internal */ static /* var */_instance: ArenaCrossFinalMyBattlesWindows;
    }
